package com.cargohu.aishouyu.operation.controller;

import com.cargohu.aishouyu.common.CommonConstants;
import com.cargohu.aishouyu.framework.page.Paging;
import com.cargohu.aishouyu.framework.response.ApiResult;
import com.cargohu.aishouyu.operation.dto.AppNoticeAddDTO;
import com.cargohu.aishouyu.operation.dto.AppNoticeUpdateDTO;
import com.cargohu.aishouyu.operation.req.AppNoticeRequest;
import com.cargohu.aishouyu.operation.resp.AppNoticeDetailVo;
import com.cargohu.aishouyu.operation.resp.AppNoticeResponse;
import com.cargohu.aishouyu.operation.service.AppNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * APP公告 控制器
 *
 * @author yww
 * @since 2023-11-29
 */
@Slf4j
@RestController
@RequestMapping(CommonConstants.API_ADMIN_PATH+"/app-notice")
@Tag(name = "APP公告管理")
public class AppNoticeController {

    @Autowired
    private AppNoticeService appNoticeService;

    /**
     * 添加APP公告
     *
     * @param appNoticeAddDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    @Operation(summary = "添加APP公告")
    public ApiResult addAppNotice(@Valid @RequestBody AppNoticeAddDTO appNoticeAddDTO) throws Exception {
        boolean flag = appNoticeService.addAppNotice(appNoticeAddDTO);
        return ApiResult.result(flag);
    }

    /**
     * 修改APP公告
     *
     * @param appNoticeUpdateDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    @Operation(summary = "修改APP公告")
    public ApiResult updateAppNotice(@Valid @RequestBody AppNoticeUpdateDTO appNoticeUpdateDTO) throws Exception {
        boolean flag = appNoticeService.updateAppNotice(appNoticeUpdateDTO);
        return ApiResult.result(flag);
    }

    /**
     * 删除APP公告
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除APP公告")
    public ApiResult deleteAppNotice(@PathVariable Long id) throws Exception {
        boolean flag = appNoticeService.deleteAppNotice(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取APP公告详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/get/{id}")
    @Operation(summary = "APP公告详情")
    public ApiResult<AppNoticeDetailVo> getAppNotice(@PathVariable Long id) throws Exception {
        AppNoticeDetailVo appNoticeDetailVo = appNoticeService.getAppNoticeById(id);
        return ApiResult.success(appNoticeDetailVo);
    }

    /**
     * APP公告分页列表
     *
     * @param appNoticeRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/page")
    @Operation(summary = "APP公告分页列表")
    public ApiResult<AppNoticeResponse> getAppNoticeList(@Valid @RequestBody AppNoticeRequest appNoticeRequest) throws Exception {
        Paging<AppNoticeResponse> paging = appNoticeService.getAppNoticeList(appNoticeRequest);
        return ApiResult.success(paging);
    }

}
